package com.yanqu.road.server.cmd.activity.autoreward.rank;

import com.yanqu.road.entity.enums.activity.jiuzhou.eJiuZhouGameZoneType;
import com.yanqu.road.entity.enums.activity.jiuzhou.eJiuZhouRoundType;
import com.yanqu.road.entity.enums.eGamePlayerEventType;
import com.yanqu.road.pb.activity.AutoSendRewardProto;
import com.yanqu.road.server.manager.activity.jiuzhou.CrossJiuZhouMgr;
import com.yanqu.road.server.manager.activity.jiuzhou.activity.CrossJiuZhouActivity;
import com.yanqu.road.entity.activity.jiuzhou.rank.CrossJiuZhouRankListModel;
import com.yanqu.road.entity.activity.jiuzhou.rank.JiuZhouRank;

public class JiuZhouActivityRank extends BaseCrossRank{

    public JiuZhouActivityRank(int activityId) {
        super(activityId);
    }

    @Override
    public AutoSendRewardProto.CrossUserRankMsg.Builder getCrossUserRankMsg() {
        AutoSendRewardProto.CrossUserRankMsg.Builder msg = AutoSendRewardProto.CrossUserRankMsg.newBuilder();
        msg.setActivityId(activityId);
        //先去拿活动
        CrossJiuZhouActivity activity = CrossJiuZhouMgr.getActivity(activityId);
        if (activity != null){
            CrossJiuZhouRankListModel rankListByRoundAndType = activity.getRankListByRoundAndType(eJiuZhouGameZoneType.elite.getValue(), eJiuZhouRoundType.score.getValue());
            if (rankListByRoundAndType!=null){
                int rank = 0;
                for (JiuZhouRank rankData : rankListByRoundAndType.getRankList()) {
                    long userId = rankData.getUserId();
                    rank++;
                    addUserRankData(msg, eGamePlayerEventType.JiuZhouEliteScoreRoundRank.getValue(), userId, rank);
                }
            }
            rankListByRoundAndType = activity.getRankListByRoundAndType(eJiuZhouGameZoneType.elite.getValue(), eJiuZhouRoundType.knockout.getValue());
            if (rankListByRoundAndType!=null){
                int rank = 0;
                for (JiuZhouRank rankData : rankListByRoundAndType.getRankList()) {
                    long userId = rankData.getUserId();
                    rank++;
                    addUserRankData(msg, eGamePlayerEventType.JiuZhouEliteOutRoundRank.getValue(), userId, rank);
                }
            }
            rankListByRoundAndType = activity.getRankListByRoundAndType(eJiuZhouGameZoneType.master.getValue(), eJiuZhouRoundType.score.getValue());
            if (rankListByRoundAndType!=null){
                int rank = 0;
                for (JiuZhouRank rankData : rankListByRoundAndType.getRankList()) {
                    long userId = rankData.getUserId();
                    rank++;
                    addUserRankData(msg, eGamePlayerEventType.JiuZhouMasterScoreRoundRank.getValue(), userId, rank);
                }
            }
            rankListByRoundAndType = activity.getRankListByRoundAndType(eJiuZhouGameZoneType.master.getValue(), eJiuZhouRoundType.knockout.getValue());
            if (rankListByRoundAndType!=null){
                int rank = 0;
                for (JiuZhouRank rankData : rankListByRoundAndType.getRankList()) {
                    long userId = rankData.getUserId();
                    rank++;
                    addUserRankData(msg, eGamePlayerEventType.JiuZhouMasterOutRoundRank.getValue(), userId, rank);
                }
            }
            rankListByRoundAndType = activity.getRankListByRoundAndType(eJiuZhouGameZoneType.king.getValue(), eJiuZhouRoundType.score.getValue());
            if (rankListByRoundAndType!=null){
                int rank = 0;
                for (JiuZhouRank rankData : rankListByRoundAndType.getRankList()) {
                    long userId = rankData.getUserId();
                    rank++;
                    addUserRankData(msg, eGamePlayerEventType.JiuZhouKingScoreRoundRank.getValue(), userId, rank);
                }
            }
            rankListByRoundAndType = activity.getRankListByRoundAndType(eJiuZhouGameZoneType.king.getValue(), eJiuZhouRoundType.knockout.getValue());
            if (rankListByRoundAndType!=null){
                int rank = 0;
                for (JiuZhouRank rankData : rankListByRoundAndType.getRankList()) {
                    long userId = rankData.getUserId();
                    rank++;
                    addUserRankData(msg, eGamePlayerEventType.JiuZhouKingOutRoundRank.getValue(), userId, rank);
                }
            }

        }



        return msg;
    }

    @Override
    public AutoSendRewardProto.CrossUnionRankMsg.Builder getCrossUnionRankMsg() {
        return null;
    }
}
